// JavaScript Document
function confirm_ajaxdelete(_title,_url,_id){
    if(confirm(_title)){
        $.ajax({
            url: _url,
            type: 'GET',
            dataType: 'html',
            error: function(){
                alert('Ajax delete error!');
            },
            success: function(html){
                if(html == 'OK'){
                    $("#"+_id).remove();
                }else{
                    alert(html);
                }
            }
        });
    }
}

function confirm_ajax(_title,_url,_id){
    if(confirm(_title)){
        ajaxLoad(_url, _id);
    }
}

function ajaxLoad(_Url, _ResultContentId){
    $.ajax({
        url: _Url,
        type: 'GET',
        dataType: 'html',
        error: function(){
            $("#"+_ResultContentId).html('Loading error!').show('slow');
        },
        success: function(html){
            if(html != '') $("#"+_ResultContentId).html(html);
        }
    });
}

function ajaxPost(_Form, _ResultContentId, _Urlpost){
    var _Url ='';
    if(isEmpty(_Urlpost)){
        _Url = $("#"+_Form).attr("action");
    }else{
        _Url = _Urlpost;
    }
    var form_data = $("#"+_Form).serialize();
    $("#"+_ResultContentId).html('<img src="'+_baseurl+'/images/loading.gif" width="16" border="0" align="absmiddle" alt="Loading...">');
    $.ajax({
        url: _Url,
        type: 'POST',
        data: form_data,
        dataType: 'html',
        error: function(){
            window.location.href = _baseurl;
        },
        success: function(html){
            $("#"+_ResultContentId).html(html);
        }
    });
}


function checkAll(listchkOneName,chkAllobj){
    var list = document.getElementsByName(listchkOneName);
    for (var i = 0; i < list.length; i++){
        list[i].checked = chkAllobj.checked;
    }
}

function checkOne(listchkOneName,chkAllId,chkOne){
    var kt = true;
    var list = document.getElementsByName(listchkOneName);
    var checkAll = document.getElementById(chkAllId);
    if(chkOne.checked){
        for (var i = 0; i < list.length; i++){
            if(list[i].checked != chkOne.checked){
                kt = false;
                break;
            }
        }
        if(kt) checkAll.checked = chkOne.checked;
    }else if(checkAll.checked){
        checkAll.checked = chkOne.checked;
    }
}

function imagemanager(_objid) {
    window.KCFinder = {};
    window.KCFinder.callBack = function(url) { 
        window.KCFinder = null;
        $('#'+_objid).val(url.replace(_baseurl, ''));
    };
    window.open(_baseurl + 'jscripts/kcfinder/browse.php?lang=vi', 'kcfinder_textbox',
        'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=0, width=700, height=500'
        );
}


function confirm_change(_idcomplete, _idvalue){
    if($('#'+_idvalue).val() == _idcomplete){
        if(!confirm('Are you sure complete this?')){
            $('#'+_idvalue).val($('#hidden_'+_idvalue).val());
        }
    }
    $('#hidden_'+_idvalue).val($('#'+_idvalue).val());
}

function save_ajax(_urlsave, _idresult, _idvalue){
    _urlsave = _urlsave + '/' + $('#hidden_'+_idvalue).val();
    $('#dialog_'+_idvalue).dialog( "close" );
    ajaxLoad(_urlsave, _idresult);
}